import java.awt.Color;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;

public class RPGFish extends Fish
{
    protected int level;
    protected double exp;
    protected int strength;
    protected int defense;
    protected int speed;
    protected Random gen;

    public RPGFish(Environment env, Location loc)
    {
        super(env, loc);
        initializeRPGFish();
    }

    public RPGFish(Environment env, Location loc, Direction dir)
    {
        super(env, loc, dir);
        initializeRPGFish();
    }

    public RPGFish(Environment env, Location loc, Direction dir, Color col)
    {
        super(env, loc, dir, col);
        initializeRPGFish();
    }
    
    public void initializeRPGFish()
    {
        level = 1;
        exp = 0;
        strength = 1;
        defense = 1;
        speed = 1;
        gen = new Random();
    }
    
    public void upkeep() {
        if (exp >= Math.pow(level, 2)) {
            System.out.println(ident() + " has LEVELED UP!!!");
            level++;
            exp = 0;
            strength += gen.nextInt(3) + 1;
            defense += gen.nextInt(3) + 1;
            if (gen.nextInt(10) == 0 && speed < min(environment().numCols(), environment().numRows())) {
                speed++;
            }
        }
        System.out.println(ident() + "@lv" + level + " exp: " + exp);
        System.out.println("Str: " + strength + " Def: " + defense + " Spd: " + speed);
    }
    
    public void act() {
        move();
        eat();
    }
    
    public void eat() {
        Location inFront = environment().getNeighbor(location(), direction());
        if (!environment().isEmpty(inFront) && environment().isValid(inFront)) {
            Fish victim = (Fish)environment().objectAt(inFront);
            if (victim instanceof RPGFish) {
                System.out.println("ITS RPG TIME!!!");
                if (strength > ((RPGFish)victim).defense()) {
                    exp += ((RPGFish)victim).level() * 4;
                    environment().remove(victim);
                } else {
                    return;
                }
            } else {
                exp += 4;
                environment().remove(victim);
            }
            upkeep();
        }
    }
    
    public void die() {
        environment().remove(this);
    }
    
    public boolean breed() {
        return false;
    }
    
    public int min(int a, int b) {
        if (a < b) return a;
        else return b;
    }
    
    public int strength() {
        return strength;
    }
    
    public int defense() {
        return defense;
    }
    
    public int speed() {
        return speed;
    }
    
    public int level() {
        return level;
    }
    
    public String toString() {
        return ident() + "@ lv. " + level + ". Exp: " + exp + " Str: " + strength + " Def: " + defense + " Spd: " + speed;
    }
}